package sivan.socket;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.net.ServerSocket;
import java.net.Socket;

public class BIOServiceTest {

    public static void main(String[] args) throws Exception {
        ServerSocket server = new ServerSocket(8090);
        System.out.println("step1: new ServerSocket(8090)");
        while (true) {
            Socket client = server.accept();
            System.out.println("step2：接收到客户端client" + client.getPort());

            new Thread(() -> {
                System.out.println(Thread.currentThread().getName() + ":连接成功");
                System.out.println(Thread.currentThread().getName() + ":准备接收数据");
                byte[] bytes = new byte[1024];
                try {
                    client.getInputStream().read(bytes);
                } catch (IOException e) {
                    e.printStackTrace();
                }
                System.out.println("接收到了数据：" + new String(bytes));
            }).start();
        }
    }
}
